package com.zhouz.admin.app.aop;

import com.zhouz.admin.app.db.domain.SysAdmin;
import com.zhouz.admin.app.db.vo.LoginUserVo;
import lombok.extern.log4j.Log4j2;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 接口切面 记录日志 存入MongoDB
 *
 * @Author 张鹏
 * @Date 2018/8/24 14:21
 */
@Aspect
@Component
@Log4j2
public class LogAdminAop extends LogAopBase {

    @Override
    public LoginUserVo getLoginUser() {
        Subject currentUser = SecurityUtils.getSubject();
        if(currentUser.getPrincipal() == null){
           return new LoginUserVo();
        }else{
            SysAdmin admin = (SysAdmin) currentUser.getPrincipal();
            return new LoginUserVo(admin.getId().toString(),admin.getUsername());
        }
    }
}
